import Vue from 'vue'
import apiSeller from '../../api/seller'

const state = {
  data: {},
}

// getters
const getters = {
  getSeller: (state) => {
    return state.data
  }
}

// actions
const actions = {
  initSeller({ commit, state }, obj) {
    if (state.data.name) {
      return state.data
    } else {
      apiSeller.getSeller(
        obj.sellerId,
        (returnData) => {
          commit('initSeller', { data: returnData })
        },
      )
      return { errno: 1, msg: 'get nothing' }
    }
  },
}

// mutations
const mutations = {
  initSeller(state, obj) {
    Vue.set(state, 'data', obj.data)
  }
}

export default {
  namespaced: true,
  state,
  getters,
  actions,
  mutations,
}
